//
//  CQPopEnum.m
//  01-OC微博
//
//  Created by 陈乾 on 15/10/27.
//  Copyright © 2015年 陈乾. All rights reserved.
//

#import "CQPopEnum.h"


@implementation CQPopEnum

+(instancetype)showWithFrame:(CGRect)rect
{
    //创建
    CQPopEnum *popEnum = [[CQPopEnum alloc] initWithFrame:rect];
    //设置背景
    popEnum.userInteractionEnabled = YES;
    popEnum.image = [UIImage imageNamed:@"popover_background"];
    //添加到主窗口
    [CQKeyWindow addSubview:popEnum];
    //返回
    return popEnum;
}

+(void)hide
{
    for (CQPopEnum* popEnum in CQKeyWindow.subviews) {
        if ([popEnum isKindOfClass:self]) {
            //表示可以移除
            [popEnum removeFromSuperview];
        }
    }

}

//设置内容视图
-(void)setContentView:(UIView *)contentView
{
    //先移除之前
    [_contentView removeFromSuperview];
    _contentView = contentView;
    _contentView.backgroundColor = [UIColor clearColor];
    [self addSubview:_contentView];
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    //计算内容尺寸
    CGFloat y = 9;
    CGFloat margin = 5;
    CGFloat x = margin;
    CGFloat w = self.frame.size.width - 2 * margin;
    CGFloat h = self.frame.size.height - y - margin;
    
    _contentView.frame = CGRectMake(x, y, w, h);

    

}


@end
